package JSP;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import pojo.User;
import utils.JDBCutils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class SearchStudentServlet1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        System.out.println(name);
        QueryRunner queryRunner = new QueryRunner();
        Connection conn = JDBCutils.getConn();
        String sql = "SELECT `username` FROM books WHERE `username` LIKE  ?\"%\" ";
        try {
            List<User> users = queryRunner.query(conn, sql, new BeanListHandler<User>(User.class), name);
            System.out.println(users);
            req.setAttribute("Stus",users);
            req.getRequestDispatcher("/search1.jsp").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
